/**
 * @file       typedefine.h
 * @brief      TODO
 * @author     hzheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef TYPEDEFINE_H_
#define TYPEDEFINE_H_

namespace NS_LCD_AFW
{

#ifndef NULL
//#define NULL ((void *)0)
#define NULL (0)
#endif

#define OBJ_NEW(type,pObj)                                        \
	do                                                            \
	{                                                             \
		try                                                       \
		{                                                         \
			pObj = new type();                                    \
		}                                                         \
		catch(...)                                                \
		{                                                         \
			pObj = NULL;                                          \
		}                                                         \
	}                                                             \
	while(0)

#define  OBJ_DELETE(pObj)                                         \
	do                                                            \
	{                                                             \
		if (NULL != pObj)                                         \
		{                                                         \
			delete pObj;                                          \
			pObj = NULL;                                          \
		}                                                         \
	}                                                             \
    while(0)

#define  OBJ_DESTORY(pObj)                                        \
	do                                                            \
	{                                                             \
		if (NULL != pObj)                                         \
		{                                                         \
			pObj->destory();                                      \
			pObj = NULL;                                          \
		}                                                         \
	}                                                             \
    while(0)

#define ARRAY_NEW(type,len,pBuf)                                  \
	do                                                            \
	{                                                             \
		try                                                       \
		{                                                         \
			pBuf = new type[len];                                 \
/*			memset(pBuf,(int)0x00,sizeof(type) * (size_t)len);*/  \
		}                                                         \
		catch(...)                                                \
		{                                                         \
			pBuf = NULL;                                          \
		}                                                         \
	}                                                             \
	while(0)


#define  ARRAY_DELETE(pArr)                                       \
	do                                                            \
	{                                                             \
		if (NULL != pArr)                                         \
		{                                                         \
			delete []pArr;                                        \
			pArr = NULL;                                          \
		}                                                         \
	}                                                             \
	while(0)

#define MEMORY_BARRIER()

#define GEN_BIT(var,which) ( var = ((0x01u) << (which)))
#define SET_BIT(bit,mask) ((bit) |= (mask))
#define UNSET_BIT(bit,mask) ((bit) &= (~(mask)))
#define ISBIT_SETTED(bit,mask) ((((bit) &(mask)) ? true : false))


#define INVALID_POSITION               (-1)
#define INVALID_LENTGH                 (-1)
#define INVALID_EVENT_CODE             (-1)
#define INVALID_EVENT_ID               (-1)
#define INVALID_PARAM                  (-1)
#define INVALID_TIME                   (-1)



#define AFW_EVENT_ID_START             (10000000)
#define DOWN_KEY_PRESSED_EVENT_ID      (AFW_EVENT_ID_START + 1)
#define UP_KEY_PRESSED_EVENT_ID        (AFW_EVENT_ID_START + 2)
#define RIGHT_KEY_PRESSED_EVENT_ID     (AFW_EVENT_ID_START + 3)
#define LEFT_KEY_PRESSED_EVENT_ID      (AFW_EVENT_ID_START + 4)

#define ENTER_KEY_PRESSED_EVENT_ID     RIGHT_KEY_PRESSED_EVENT_ID
#define ESC_KEY_PRESSED_EVENT_ID       LEFT_KEY_PRESSED_EVENT_ID

#define PANEL_CLOSE_EVENT_ID            (AFW_EVENT_ID_START + 7)

#define ID_OK                           (AFW_EVENT_ID_START + 8)
#define ID_CANCLE                       (ID_OK + 1)

#define USER_EVENT_ID_START            (10000000)





#define IP_ADDRESS_WIDTH                  (15)
#define IP_ADDRESS_HEIGHT                 (1)

#define DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CLASS_NAME)   \
	private:                                                        \
	const CLASS_NAME &operator=(const CLASS_NAME & );               \
	CLASS_NAME(const CLASS_NAME &)
}
/* namespace NS_LCD_AFW */

#endif /* TYPEDEFINE_H_ */
